package com.example.customview

import android.animation.*
import android.graphics.PointF
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.example.customview.view.*
import com.sample.base.utils.dp
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_main)
        setContentView(R.layout.two_pager_layout)
//        startCircleAnimator2()
//        setupTagView()
//        startCircleAnimator()
//        startPointFAnimator()
//        startStringAnimator()
//        startClipAnimator()
//        checkbox.isChecked = false
//
//        checkbox.setOnCheckedChangeListener { buttonView, isChecked ->
//            view.useFloatingLabel = isChecked
//        }
    }

    private fun setupTagView() {
        view.removeAllViews()
        for (element in provinces) {
            val marginLayoutParams = ViewGroup.MarginLayoutParams(
                ViewGroup.MarginLayoutParams.WRAP_CONTENT,
                ViewGroup.MarginLayoutParams.WRAP_CONTENT
            )

            view.addView(ColoredTextView(this, null).apply {
                text = element
            }
                , marginLayoutParams)
        }

    }

    private fun startClipAnimator() {
        val topFlip = PropertyValuesHolder.ofFloat("topFlip", -45f)
        val bottomFlip = PropertyValuesHolder.ofFloat("bottomFlip", 45f)
        val rotateAngle = PropertyValuesHolder.ofFloat("rotateAngle", 180f)
        val ofPropertyValuesHolder =
            ObjectAnimator.ofPropertyValuesHolder(view, topFlip, bottomFlip, rotateAngle)
        ofPropertyValuesHolder.startDelay = 1000
        ofPropertyValuesHolder.duration = 3000
        ofPropertyValuesHolder.start()
    }

    private fun startStringAnimator() {
        val animator = ObjectAnimator.ofObject(
            view, "province", ProvinceView.ProvinceTypeEvaluator(),
            provinces[provinces.size - 1]
        )
        animator.startDelay = 1000
        animator.duration = 8000
        animator.start()

    }

    private fun startPointFAnimator() {
        val animator = ObjectAnimator.ofObject(
            view, "point", PointFView.PointFEvaluator(),
            PointF(300.dp.toFloat() - 10.dp, 300.dp.toFloat() - 10.dp)
        )
        animator.startDelay = 1000
        animator.duration = 2000
        animator.start()

    }

    private fun startCircleAnimator() {
        val animation = ObjectAnimator.ofFloat(
            view, "radius",
            188.dp.toFloat()
        )
        animation.startDelay = 1000
        animation.start()

    }

    private fun startCircleAnimator2() {
//        val progressAnimator = ObjectAnimator.ofFloat(
//            sportView, "progress",
//            0f, 66f
//        )
//        val textAnimator = ObjectAnimator.ofObject(
//            sportView, "progressText", ZProgressView.TextTypeEvaluator(), 6868
//
//        )
//        val animatorSet = AnimatorSet().apply {
//            play(progressAnimator).with(textAnimator)
//            startDelay = 1000
//            duration = 3000
//            interpolator = DecelerateInterpolator()
//
//        }
//        animatorSet.start()
        sportView.setProgressWithAnimator(88f,8888)
//        sportView.progress=88f
//        sportView.progressText=1818

    }
}
